﻿@{
    ViewBag.Title = "登录";
}
<div class="layui-row">
    <div class="layui-col-md4">
        <div style="width:100%;opacity: 0;">
            W
        </div>
    </div>
    <div class="layui-col-md4">
        <div style="width:100%;padding:160px 0px;">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;text-align:center;">
                <legend>用户登录</legend>
            </fieldset>
            <form class="layui-form">
                <div class="layui-form-item">
                    <div class="">
                        <input type="text" id="email" name="email" required lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="">
                        <input type="password" id="pwd" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="">
                        <input type="text" style="width:70%;float:left;" id="ValidateCode" name="ValidateCode" required lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">
                        <img id="valiCode" style="cursor: pointer;width: 76px;padding-left: 25px;" src="~/Home/GetValidateCode" alt="验证码" />
                    </div>
                </div>

                <div class="layui-form-item" pane="">
                    <div class="">
                        <input type="checkbox" name="remaber_me" lay-skin="primary" title="记住密码" checked="">
                      
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="">
                        <button type="button" class="layui-btn" style="width:100%;" onclick="login()">立即登录</button>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="">
                        <a href="###" style="color:green;">忘记密码？</a>
                        <a href="/Home/Register" style="color:green;float:right;">立即注册</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-col-md4" style="">
        <div style="width:100%;opacity: 0;">
            W
        </div>
    </div>
</div>

<script>
    $(function () {
        $("#valiCode").bind("click", function () {
            this.src = "../Home/GetValidateCode?time=" + (new Date()).getTime();
        });
    });
    function login() {
        if ($("#email").val() == "") {
            layer.alert('请输入账号');
            return;
        }
        if ($("#pwd").val() == "") {
            layer.alert('请输入密码');
            return;
        }
        if ('@ViewBag.check_yzm' == 'true') {
            if ($("#ValidateCode").val() == "") {
                layer.alert('请输入验证码');
                return;
            }
        }

        var email = $("#email").val();
        var pwd = $("#pwd").val();
        if (email.indexOf('script') != -1 || pwd.indexOf('script') != -1) {
            layer.alert('用户不存在');
            return;
        }

        layer.load(1);
        $.ajax({
            url: '/Home/Login',
            type: 'POST',
            data: {
                email: email,
                password: pwd,
                ValidateCode: $("#ValidateCode").val()
            },
            dataType: 'text',
            success: function (data) {
                layer.closeAll('loading');
                if (data == "ok") {
                    location.href = "/Home/Index";
                } else {
                    layer.alert(data, false);
                    return false;
                }
            }
        });
    }
</script>
